package com.yequan.hbb.view;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.yequan.hbb.R;
import com.yequan.hbb.adapter.DynamicAdapter;
import com.yequan.hbb.entries.AnswerEntries;
import com.yequan.hbb.entries.QuestionEntries;
import com.yequan.hbb.presenter.AnswerPresenter;
import com.yequan.hbb.presenter.QuestionPresenter;

import java.util.List;

public class Question2Activity extends AppCompatActivity implements QuestionView<QuestionEntries,AnswerEntries>{

    private QuestionPresenter questionPresenter;
    private ListView recycler;
    private TextView coverTitle;
    private DynamicAdapter adapter;
    private AnswerPresenter answerPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_question2);
        View headerView = LayoutInflater.from(this).inflate(R.layout.item_ques2_header, recycler, false);
        recycler = (ListView) findViewById(R.id.question2_recycler);
        coverTitle = (TextView) headerView.findViewById(R.id.question2_covertitle);
        recycler.addHeaderView(headerView);
        adapter = new DynamicAdapter(this);
        recycler.setAdapter(adapter);

        int contentId = getIntent().getIntExtra("contentId", 0);
        questionPresenter = new QuestionPresenter();
        questionPresenter.attach(this);
        questionPresenter.getQuestionData(contentId);
        answerPresenter = new AnswerPresenter();
        answerPresenter.attach(this);
        answerPresenter.getAnswerData(contentId);
    }



    @Override
    public void showQuestion(QuestionEntries questionEntries) {
        QuestionEntries.DataBean.ContentBean content = questionEntries.getData().getContent();
        String description = content.getDescription();
       // Log.e("自定义标签", "类名==Question2Activity" + "方法名==showQuestion=====:" + description);
        coverTitle.setText(content.getTitle());

    }

    @Override
    public void showAnswer(AnswerEntries answerEntries) {
        List<AnswerEntries.DataBean.ContentBean.AnswerBean.DataBean2> data = answerEntries.getData().getContent().getAnswer().getData();
        adapter.addAll(data);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        questionPresenter.dettch();
    }
}
